import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_deer/mvp/base_page_presenter.dart';
import 'package:flutter_deer/net/base_entity.dart';
import 'package:flutter_deer/net/net.dart';
import 'package:flutter_deer/setting/iview/version_iview.dart';
import 'package:flutter_deer/setting/models/version_entity.dart';


class VersionPresenter extends BasePagePresenter<VersionIMvpView> {

  @override
  void initState() {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      /// 接口请求例子
      /// get请求参数queryParameters  post请求参数params
      String url = HttpApi.versionInfo;
      bool? request = false;
      if(Platform.isAndroid){
        url = url.replaceAll('{platform}', 'android');
        request = true;
      }else if(Platform.isIOS){
        url = url.replaceAll('{platform}', 'ios');
        request = true;
      }
      if(request==true) {
        asyncRequestNetwork<BaseEntity<VersionEntity>>(Method.get,
            url: url,
            onSuccess: (data) {
              view.setVersion(data?.data);
            },
            onError: (code, msg) {

            }
        );
      }
    });
  }

}
